<?php

namespace app\common\model\events;

use think\Model;


class Sign extends Model
{





    // 表名
    protected $name = 'events_sign';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'gender_text',
        'state_text',
        'events_array',
        'num_int',
    ];
    public function getNumIntAttr($v, $d)
    {
        return Order::where('sign_id', $d['id'])->where('status', '1')->count();
    }
    public function getEventsArrayAttr($v, $d)
    {
        return $d['events_info'] ? json_decode($d['events_info'], true) : [];
    }


    public function getGenderList()
    {
        return ['male' => __('Gender male'), 'female' => __('Gender female')];
    }

    public function getStateList()
    {
        return ['0' => __('State 0'), '10' => __('State 10'), '-1' => __('State -1')];
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function events()
    {
        return $this->belongsTo('app\common\model\events\Events', 'e_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function category()
    {
        return $this->belongsTo('Category', 'c_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
